from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator

# Create your models here.

USERNAME_MAX_LENGTH = 32
NICKNAME_MAX_LENGTH = 32
PASSKEY_MAX_LENGTH = 32

MESSAGE_CONTENT_MAX_LENGTH = 1024

CATEGORY_DESCRIPTION_MAX_LENGTH = 16

class User(models.Model):
    username = models.CharField(max_length=USERNAME_MAX_LENGTH)
    nickname = models.CharField(max_length=NICKNAME_MAX_LENGTH)
    passkey = models.CharField(max_length=PASSKEY_MAX_LENGTH)

    def __unicode__(self):
        return self.username

class Category(models.Model):
    description = models.CharField(max_length=CATEGORY_DESCRIPTION_MAX_LENGTH)

    def __unicode__(self):
        return self.description

class Message(models.Model):
    user = models.ForeignKey(User)
    category = models.ForeignKey(Category)
    content = models.CharField(max_length=MESSAGE_CONTENT_MAX_LENGTH)
    time = models.DateTimeField('date published')
    latitude = models.FloatField(default=0,
            validators=[MinValueValidator(-90.0),MaxValueValidator(90.0)]
    )
    longitude = models.FloatField(default=0,
            validators=[MinValueValidator(-180.0),MaxValueValidator(180.0)]
    )

    def __unicode__(self):
        return self.content
